<?php
class messageMod extends commonMod{

	// 留言界面
	public function index() {
		$this->assign("nav_8", TRUE);		
		$this->display('message_index');
	}

	// 留言提交
	public function post() {

		if ($_POST) {
			// 处理留言
			
			$title 	 = __safe('title');
			$content = __safe('content');
			$name 	 = __safe('name');
			$tel 	 = __safe('tel');
			$email   = __safe('email');
			$vcode   = __safe('vcode');

			// 验证码
			if ($_SESSION['lebang_vcode'] != $vcode or $vcode=='') {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'验证码有误\');history.go(-1);</script>';
				exit;
			}

			// 数据是否为空
			if (empty($title) or empty($content) or empty($name) or empty($tel) or empty($email)) {
				echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
				echo '<script>alert(\'标题、留言、联系人、电话、邮箱是必填项\');history.go(-1);</script>';
				exit;
			}

			@__query("INSERT INTO {tabpre}message (`title`, `content`, `tel`, `email`, `name`, `datetime`, `show`, `recover`) VALUES ('$title', '$content', '$tel', '$email', '$name', '".date('Y-m-d h:i:s')."', 0, 0) ");

			echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
			echo '<script>alert(\'留言成功，我们会尽快与您取得联系，服务热线：0571-88887777\');history.go(-1);</script>';
			exit;
		}
	}
}